﻿using System;
using System.Diagnostics;
using System.Windows.Forms;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YJKCodeBase.WinForm;
using YJKFloor.FloorEditor;
using YJKView;

namespace YJKFloor.FloorOffset
{
	[Transaction(TransactionMode.Manual)]
	[Regeneration(RegenerationOption.Manual)]
	public class CmdFloorOffset : IExternalCommand
	{
		public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elems)
		{
			Result result;
			try
			{
				if (cmdData == null)
				{
					throw new System.ArgumentNullException("commandData");
				}
				CmdViewType types = (CmdViewType)121;
				if (SwitchView.SetUsableView(types, cmdData) != Autodesk.Revit.UI.Result.Succeeded)
				{
					result = Autodesk.Revit.UI.Result.Failed;
				}
				else
				{
					if (CmdFloorOffset._hWndRevit == null)
					{
						Process currentProcess = Process.GetCurrentProcess();
						IntPtr mainWindowHandle = currentProcess.MainWindowHandle;
						CmdFloorOffset._hWndRevit = new WindowHandle(mainWindowHandle);
					}
					FloorOffsetEditor floorOffsetEditor = new FloorOffsetEditor(cmdData);
					Result result2 = floorOffsetEditor.Offset(ref msg);
					if (result2 == null)
					{
						result = result2;
					}
					else
					{
						MessageBox.Show("楼板修改未成功。", "盈建科提示");
						result = result2;
					}
				}
			}
			catch (Exception)
			{
				result = Autodesk.Revit.UI.Result.Failed;
			}
			return result;
		}

		public static WindowHandle _hWndRevit;
	}
}
